import { execute } from "../../database/connector";

import { UserRolesQueries } from "../queries/user-roles.query";
import { IUserRoles } from "../../models/user-roles.model";

/**
 * gets active researchGroupMemberList
 */
export const getUserRolesList = async () => {
  return execute<IUserRoles[]>(UserRolesQueries.GetUserRoles, []);
};

/**
 * gets a UserRoles based on id provided
 */
export const getUserRolesById = async (id: IUserRoles['id']) => {
  return execute<IUserRoles>(UserRolesQueries.GetUserRolesById, [id]);
};

/**
 * gets a UserRoles based on group id provided
 */
export const getUserRolesByUserId = async (userId: IUserRoles['userId']) => {
  return execute<IUserRoles>(UserRolesQueries.GetUserRolesByUserId, [userId]);
};

/**
 * adds a new active UserRoles record
 */
export const insertUserRoles = async (userRoles: IUserRoles[]) => {
  const result = await execute<{ affectedRows: number }>(UserRolesQueries.AddUserRoles, [
    userRoles
  ]);
  return result.affectedRows > 0;
};


/**
 * updates UserRoles information based on the id provided
 */
 export const deleteUserRoles = async (userId: IUserRoles['userId']) => {
  const result = await execute<{ affectedRows: number }>(UserRolesQueries.DeleteUserRolesByUserId, [
    userId
  ]);
  return result.affectedRows > 0;
};